package com.csdn.listener;

import com.csdn.config.BaseConfig;
import org.apache.commons.io.monitor.FileAlterationMonitor;
import org.apache.commons.io.monitor.FileAlterationObserver;
import java.io.File;
import java.util.Set;

public class FileMonitor implements ConfigMonitor {
    private String Path = "/testfile";

    public void listen(Set<Class<? extends BaseConfig>> classz) throws Exception {
        File dir = new File(Path);
        dir.mkdirs();
        FileAlterationObserver observer = new FileAlterationObserver(Path);
        FileListener fileListener = new FileListener(classz);
        observer.addListener(fileListener);
        FileAlterationMonitor monitor = new FileAlterationMonitor(1000);
        monitor.addObserver(observer);
        monitor.start();
    }

}
